﻿using System;
using System.Windows.Forms;

namespace com.orange.examination.Teacher
{
    public partial class TeacherChangePwd : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["teacher"] == null)
            {
                Response.Redirect("../LoginAndRegister/Login.aspx");
            }
        }
        protected void btnchange_Click(object sender, EventArgs e)
        {
            if (txtNewPwd.Text == "" || txtNewPwdA.Text == "" || txtOldPwd.Text == "")//检查信息输入是否完整
            {
                Response.Write("<script type=text/javascript>alert('请将信息填写完整！')</script>");
                return;
            }
            else
            {
                //检查旧密码输入是否正确
                if (BaseClass.CheckTeacher(Session["teacher"].ToString(), txtOldPwd.Text.Trim()))
                {
                    if (txtNewPwd.Text.Trim() != txtNewPwdA.Text.Trim())//检查两次输入的新密码是否相等
                    {
                        Response.Write("<script type=text/javascript>alert('两次密码不一致！')</script>");
                        return;
                    }
                    else
                    {
                        string strsql = "update tb_Teacher set TeacherPwd='" + txtNewPwdA.Text.Trim() + "' where TeacherNum='" + Session["teacher"].ToString() + "'";
                        BaseClass.OperateData(strsql);//更新数据表

                        Response.Write("<script type=text/javascript>alert('密码修改成功！')</script>");
                        txtNewPwd.Text = ""; //清空文本框
                        txtNewPwdA.Text = "";//清空文本框
                        txtOldPwd.Text = "";//清空文本框
                    }
                }
                else
                {
                    MessageBox.Show("旧密码输入错误");
                    return;
                }
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            txtNewPwd.Text = ""; //清空文本框
            txtNewPwdA.Text = "";//清空文本框
            txtOldPwd.Text = "";//清空文本框
        }
    }
}